package com.pet.client.common;

import java.io.File;

import com.pet.framework.page.ATTPage;
import com.pet.framework.page.Page;
import com.pet.framework.page.PagerFactory;
import com.pet.framework.util.BaseAction;
import com.pet.server.bo.common.PetService;
import com.pet.server.po.PetAdopt;
import com.pet.server.po.PetAdoptItem;
import com.pet.server.po.PetInfo;
import com.pet.server.po.PetMissing;
import com.pet.server.po.PetSay;
import com.pet.server.po.PetTimeLine;
import com.pet.server.po.ProductView;
import com.pet.system.constants.ATTSystem;

public class PetAction extends BaseAction{

	public PetService petService;
	public Integer id;
	public Integer adoptId;
	public File mp3File;
	public String mp3FileFileName;
	private PetSay petSay;
	private PetMissing petMissing;
	private PetAdopt petAdopt; 
	private PetAdoptItem  petAdoptItem;
	private PetInfo  petInfo;
	private PetTimeLine  petTimeLine;
	
	
	
	public Integer getAdoptId() {
		return adoptId;
	}

	public void setAdoptId(Integer adoptId) {
		this.adoptId = adoptId;
	}

	/**
	 * @return the petTimeLine
	 */
	public PetTimeLine getPetTimeLine() {
		return petTimeLine;
	}

	/**
	 * @param petTimeLine the petTimeLine to set
	 */
	public void setPetTimeLine(PetTimeLine petTimeLine) {
		this.petTimeLine = petTimeLine;
	}

	/**
	 * @return the petInfo
	 */
	public PetInfo getPetInfo() {
		return petInfo;
	}

	/**
	 * @param petInfo the petInfo to set
	 */
	public void setPetInfo(PetInfo petInfo) {
		this.petInfo = petInfo;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	
	
	public File getMp3File() {
		return mp3File;
	}

	public void setMp3File(File mp3File) {
		this.mp3File = mp3File;
	}


	public String getMp3FileFileName() {
		return mp3FileFileName;
	}

	public void setMp3FileFileName(String mp3FileFileName) {
		this.mp3FileFileName = mp3FileFileName;
	}

	public PetSay getPetSay() {
		return petSay;
	}

	public void setPetSay(PetSay petSay) {
		this.petSay = petSay;
	}
	
	
	/**
	 * @return the petAdopt
	 */
	public PetAdopt getPetAdopt() {
		return petAdopt;
	}

	/**
	 * @param petAdopt the petAdopt to set
	 */
	public void setPetAdopt(PetAdopt petAdopt) {
		this.petAdopt = petAdopt;
	}

	/**
	 * @return the petAdoptItem
	 */
	public PetAdoptItem getPetAdoptItem() {
		return petAdoptItem;
	}

	/**
	 * @param petAdoptItem the petAdoptItem to set
	 */
	public void setPetAdoptItem(PetAdoptItem petAdoptItem) {
		this.petAdoptItem = petAdoptItem;
	}

	/**
	 * @return the petMissing
	 */
	public PetMissing getPetMissing() {
		return petMissing;
	}

	/**
	 * @param petMissing the petMissing to set
	 */
	public void setPetMissing(PetMissing petMissing) {
		this.petMissing = petMissing;
	}
	/**
	 * 宠物时间线
	 * @return
	 */
	public String searchPetTimeLine(){
		Page page = PagerFactory.createPage();
		petService.searchPetTimeLine(petTimeLine, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	/**
	 * 宠物列表
	 * @return
	 */
	public String searchPetInfo(){
		Page page = PagerFactory.createPage();
		petService.searchPetInfo(petInfo, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	/**
	 * 宠物说列表
	 * @return
	 */
	public String searchPetSay(){
		Page page = PagerFactory.createPage();
		petService.searchPetInfo(petSay, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}

	public PetService getPetService() {
		return petService;
	}

	public void setPetService(PetService petService) {
		this.petService = petService;
	}
	
	public String toPetSay(){
		PetSay p=petService.getObject(id, PetSay.class);
		super.setAttr("petSay", p);
		//sPage page  
		return SUCCESS;
	}
	
	
	public String suPetSay(){
		PetSay p = petService.getObject(id,PetSay.class);
		if(null==p && null!=petSay){
			petService.savePetInfo(petSay, mp3File, mp3FileFileName);
		}else if(null!=petSay){
			petService.updatePetInfo(p, petSay, mp3File, mp3FileFileName);
		}
		return SUCCESS;
	}


	public String searchPetMissing(){
		Page page = PagerFactory.createPage();
		petService.searchPetMissing(petMissing,page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	
	/**
	 * 领养领养列表
	 * @return
	 */
	public String searchPetAdopt(){
		Page page = PagerFactory.createPage();
		petService.searchPetAdopt(petAdopt,page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	/**
	 * 宠物领养修改
	 * @return
	 */
	public String toPetAdopt(){
		PetAdopt p=petService.getObject(id, PetAdopt.class);
		super.setAttr("petAdopt", p);
		//sPage page  
		return SUCCESS;
	}
	/**
	 * 宠物领养保存
	 * @return
	 */
	public String suPetAdopt(){
		System.out.println("aaaaaaaaaaaaaaaa=");
		PetAdopt p = petService.getObject(adoptId,PetAdopt.class);
		 if(null!=petAdopt){
			petService.updatePetAdopt(p, petAdopt);
		}
		return SUCCESS;
	}
	
	public String searchPetAdoptItem(){
		Page page = PagerFactory.createPage();
		petService.searchPetAdoptItem(petAdoptItem,page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	
	/**
	 * 删除宠物申请领养列表数据
	 * @return
	 */
	public String deletePetAdoptItem(){
		PetAdoptItem v = petService.getObject(id, PetAdoptItem.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			petService.updateObject(v);
		}
		return SUCCESS;
	}
	/**
	 * 删除宠物列表数据
	 * @return
	 */
	public String deletePetInfo(){
		PetInfo v = petService.getObject(id, PetInfo.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			petService.updateObject(v);
		}
		return SUCCESS;
	}
	
	/**
	 * 删除宠物时间线数据
	 * @return
	 */
	public String deletePetTimeLine(){
		PetTimeLine v = petService.getObject(id, PetTimeLine.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			petService.updateObject(v);
		}
		return SUCCESS;
	}
	/**
	 * 删除宠物领养数据
	 * @return
	 */
	public String deletePetAdopt(){
		PetAdopt v = petService.getObject(id, PetAdopt.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			petService.updateObject(v);
		}
		return SUCCESS;
	}
	/**
	 * 删除宠物遗失数据
	 * @return
	 */
	public String deletePetMissing(){
		PetMissing v = petService.getObject(id, PetMissing.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			petService.updateObject(v);
		}
		return SUCCESS;
	}
	/**
	 * 删除宠物说数据
	 * @return
	 */
	public String deletePetSay(){
		PetSay v = petService.getObject(id, PetSay.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			petService.updateObject(v);
		}
		return SUCCESS;
	}
	
}
